package com.ktjy.sample.service;

import com.ktjy.sample.dao.PetDao;
import com.ktjy.sample.dao.PetDaoOracleImpl;
import com.ktjy.sample.entity.Pet;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("petService")
public class PetServiceImpl implements PetService{

@Resource(type= PetDaoOracleImpl.class)
    private PetDao petDao;

    @Override
    public boolean save(Pet pet) {
        int rows = petDao.insert(pet);
         delay(3000);
        return rows>0;
    }

    /**
     * 模拟业务执行所需要的时间
     * @param i
     */
    private void delay(int i) {
        try{
            Thread.sleep(i);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean modify(Pet pet) {
        delay(3000);
        return false;
    }

    @Override
    public boolean delete(Pet pet) {
        delay(3000);
        return false;
    }
}
